<%--
  Created by IntelliJ IDEA.
  User: xdzy
  Date: 2017/4/14
  Time: 13:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>验证消息</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="./resources/css/amazeui.min.css"/>
    <link rel="stylesheet" href="./resources/css/admin.css">
    <link rel="stylesheet" href="./resources/css/style.css">
</head>
<body>
<jsp:include page="common1.jsp"/>
<div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">验证消息</strong></div>
</div>
<div class="am-tabs" data-am-tabs>
    <ul class="am-tabs-nav am-nav am-nav-tabs">
        <li class="am-active"><a href="#tab1">我的申请</a></li>
        <li><a href="#tab2">收到的申请</a></li>

    </ul>

    <div class="am-tabs-bd">
        <div class="am-tab-panel am-fade am-in am-active" id="tab1">
            <table class="am-table am-table-bordered am-table-radius am-table-striped">
                <thead>
                    <tr>
                        <td>头像</td>
                        <td>用户名</td>
                        <td>昵称</td>
                        <td>分组</td>
                        <td>申请信息</td>
                        <td>状态</td>
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${requestScope.myRequest}" var="x">
                        <tr>
                            <td><img class="am-comment-avatar" width="50" height="50" src="./resources/images/${x.receiver.headImg}" alt=""></td>
                            <td>${x.receiver.username}</td>
                            <td>${x.receiver.nickName}</td>
                            <td>${x.group.gid}</td>
                            <td>${x.content}</td>
                            <td>${x.status}</td>
                            <td>
                                <button onclick="cancelConfirm(${x.frid})" type="button" class="am-btn-block am-btn am-btn-danger am-round">取消</button>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
        <div class="am-tab-panel am-fade" id="tab2">
            <table class="am-table am-table-bordered am-table-radius am-table-striped">
                <thead>
                <tr>
                    <td>头像</td>
                    <td>用户名</td>
                    <td>昵称</td>
                    <td>申请信息</td>
                    <td style="width: 20%">操作</td>
                </tr>
                </thead>
                <tbody>
                <tr>

                    <c:forEach items="${requestScope.request}" var="x">
                <tr>
                    <td><img class="am-comment-avatar" width="50" height="50" src="./resources/images/${x.sender.headImg}" alt=""></td>
                    <td>${x.sender.username}</td>
                    <td>${x.sender.nickName}</td>
                    <td>${x.content}</td>
                    <td>
                        <button onclick="acceptConfirm(${x.frid})" type="button" class=" am-btn am-btn-primary am-round">接受</button>
                        <button onclick="refuseConfirm(${x.frid})" type="button" class=" am-btn am-btn-danger am-round">拒绝</button>
                    </td>
                </tr>
                </c:forEach>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">接受申请
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <div class="am-u-sm-12 am-u-md-12 ">
                <form class="am-form am-form-horizontal">
                    <div class="am-form-group">
                        <div class="am-u-sm-12">
                           <%--<strong>对方用户名</strong><strong id="u"></strong>--%>
                            <input id="hiddenId" type="hidden" value="1">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <div class="am-u-sm-12">
                            <select id="doc-select-1">

                            </select>
                            <span class="am-form-caret"></span>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <div class="am-u-sm-12">
                            <button onclick="ok()" type="button" class="am-btn am-btn-primary am-btn-block">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<jsp:include page="common2.jsp"/>
<script>
    function cancelConfirm(id) {
        if(confirm("将要取消本次申请是否继续？")){
            //alert("删除"+id)
            window.location.href="./request_cancel.action?id="+id;
        }else{
            alert("no")
        }
    }
    function acceptConfirm(id) {
        $("#hiddenId").val(id);
        $.ajax({
            type:"post",
            url: "./groupList.action",
            data:{
            },
            dataType:"json",//返回值类型
            success:function (data) {
                var jsonData=JSON.parse(data);
                for(var i=0;i<jsonData.length;i++){
                    $("#doc-select-1").append("<option value='"+jsonData[i].gid+"'>"+jsonData[i].groupName+"</option>")
                }
            },
            error:function () {
                alert("系统异常")
            }
        });
        $("#doc-modal-1").modal("open");
    }
    function ok(){
        window.location.href="./request_accept.action?id="+$("#hiddenId").val()+"&receiverGid="+$("#doc-select-1").val();
        //alert("./views/chat/confirm_accept.action?id="+$("#hiddenId").val()+"&groupId="+$("#doc-select-1").val())
    }
    function refuseConfirm(id) {
        if(confirm("是否拒绝申请？")){
            window.location.href="./request_refuse.action?id="+id;
        }else{
            alert("no")
        }
    }
</script>
</body>
</html>
